import java.util.Random;

public class ArithmeticGenerator {
    public static void main(String[] args) {
        generateArithmeticProblems(200); // 生成5道题目
    }

    public static void generateArithmeticProblems(int count) {
        Random random = new Random();
//        System.out.println("不带结果的题目:");
//        for (int i = 0; i < count; i++) {
//            int num1 = random.nextInt(1001); // 0-1000
//            int num2 = random.nextInt(1001); // 0-1000
//            char operator = getRandomOperator(random);
//
//            // 确保除法分母不为0，且num2不能为0
//            if (operator == '/' && num2 == 0) {
//                num2 = random.nextInt(1000) + 1; // 1-1000
//            }
//
//            System.out.printf("%d %c %d = %n", num1, operator, num2);
//        }
        StringBuilder problems = new StringBuilder();
        System.out.println("不带结果的题目:");
        for (int i = 0; i < count; i++) {
            int num1 = random.nextInt(101); // 0-100
            int num2 = random.nextInt(101); // 0-100
            char operator = getRandomOperator(random);

            // 确保除法分母不为0，且num2不能为0
            if (operator == '÷') {
                num2 = random.nextInt(9) + 1; // 1-9
            }
            if(operator == 'x' && num1>=10){
                num2 = random.nextInt(9) + 1; // 1-9
            }

            String result;
            if (operator == '+') {
                result = String.valueOf(num1 + num2);
            } else if (operator == '-') {
                result = String.valueOf(num1 - num2);
            } else if (operator == 'x') {
                result = String.valueOf(num1 * num2);
            } else {
                // 除法，格式为 商...余数
                int quotient = num1 / num2;
                int remainder = num1 % num2;
                result = quotient + "..." + remainder;
            }
            System.out.printf("%d %c %d = %n", num1, operator, num2);
            problems.append(String.format("%d %c %d = %s%n", num1, operator, num2, result));
        }
        System.out.println("带结果的题目:");
        System.out.println(problems);
    }

    private static char getRandomOperator(Random random) {
        char[] operators = {'+', '-', 'x', '÷'};
        return operators[random.nextInt(operators.length)];
    }
}